package cn.com.shopec.erp.stock.commo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import cn.com.shopec.erp.multiChannel.entity.ChannelOrderReceiver;
import cn.com.shopec.erp.product.entity.ProductStock;
import cn.com.shopec.erp.product.vo.DefectReplceVo;
import cn.com.shopec.erp.purchase.vo.PurchaseRequisitionProductVo;
import cn.com.shopec.erp.purchase.vo.PurchaseReturnOrderVo;
import cn.com.shopec.erp.stock.entity.StockOut;
import cn.com.shopec.erp.stock.entity.StockOutProduct;
import cn.com.shopec.erp.stock.vo.StockOutProductVo;
import cn.com.shopec.erp.stock.vo.StockOutVo;

public class StockOutUtil {

	public static StockOutVo parseStockOutVo(StockOut stockOut) {
		if (stockOut == null) {
			return null;
		}
		StockOutVo stockOutVo = new StockOutVo();
		stockOutVo.setId(stockOut.getId());
		stockOutVo.setStockOutState(stockOut.getStockOutState());
		stockOutVo.setStockOutNo(stockOut.getStockOutNo());
		stockOutVo.setCreater(stockOut.getCreater());
		stockOutVo.setCreateTime(stockOut.getCreateTime());
		stockOutVo.setUpdater(stockOut.getUpdater());
		stockOutVo.setUpdateTime(stockOut.getUpdateTime());
		stockOutVo.setReceiverName(stockOut.getReceiverName());
		stockOutVo.setReceiverAddr(stockOut.getReceiverAddr());
		stockOutVo.setReceiverTel(stockOut.getReceiverTel());
		stockOutVo.setStockOutType(stockOut.getStockOutType());
		stockOutVo.setStockOutTypeNo(stockOut.getStockOutTypeNo());
		stockOutVo.setLogisticsNo(stockOut.getLogisticsNo());
		stockOutVo.setLogisticsOrder(stockOut.getLogisticsOrder());
		stockOutVo.setGoodsSupply(stockOut.getGoodsSupply());
		stockOutVo.setLogisticsName(stockOut.getLogisticsName());
		stockOutVo.setProductFetchType(stockOut.getProductFetchType());
		return stockOutVo;

	}

	public static StockOutProductVo parseStockOutProductVo(StockOutProduct stockOutProduct) {
		if (stockOutProduct == null) {
			return null;
		}
		StockOutProductVo stockOutVo = new StockOutProductVo();
		stockOutVo.setPurNo(stockOutProduct.getPurNo());
		stockOutVo.setProdDesc(stockOutProduct.getProdDesc());
		stockOutVo.setId(stockOutProduct.getId());
		stockOutVo.setWhNo(stockOutProduct.getWhNo());

		stockOutVo.setStockoutQuantity(stockOutProduct.getStockoutQuantity());
		stockOutVo.setProdNo(stockOutProduct.getProdNo());
		return stockOutVo;
	}

	public static StockOutProduct parseStockOutProduct(StockOutProductVo stockOutProductVo) {
		if (stockOutProductVo == null) {
			return null;
		}
		StockOutProduct stockOutProduct = new StockOutProduct();
		stockOutProduct.setPurNo(stockOutProductVo.getPurNo());
		stockOutProduct.setWhNo(stockOutProduct.getWhNo());
		stockOutProduct.setProdDesc(stockOutProductVo.getProdDesc());
		stockOutProduct.setId(stockOutProductVo.getId());
		stockOutProduct.setStockoutQuantity(stockOutProductVo.getStockoutQuantity());
		stockOutProduct.setProdNo(stockOutProductVo.getProdNo());
		return stockOutProduct;
	}

	public static ProductStock parseProductStock(StockOut stockOut, StockOutProduct stockOutProduct) {
		if (stockOutProduct == null || stockOut == null) {
			return null;
		}
		ProductStock productStock = new ProductStock();
		productStock.setCommoNo(stockOutProduct.getCommoNo());
		productStock.setProdNo(stockOutProduct.getProdNo());
		productStock.setSupNo(stockOutProduct.getSupNo());
		productStock.setWhNo(stockOutProduct.getWhNo());
		productStock.setUpdateTime(stockOut.getUpdateTime());
		return productStock;
	}

	public static StockOutVo parseStockOutProduct(ChannelOrderReceiver channelOrderReceiver) {
		if (channelOrderReceiver == null) {
			return null;
		}
		StockOutVo stockOutVo = new StockOutVo();
		stockOutVo.setReceiverTel(channelOrderReceiver.getMobile());
		stockOutVo.setReceiverName(channelOrderReceiver.getFullname());
		stockOutVo.setReceiverAddr(channelOrderReceiver.getFullAddress());
		return stockOutVo;
	}

	public static StockOutProductVo parseStockOutProductVo(Map<String, Object> map) {
		if (map == null) {
			return null;
		}
		StockOutProductVo stockOutProductVo = new StockOutProductVo();
		stockOutProductVo.setStockoutQuantity(ObjectUtil.toLong(map.get("total")));
		stockOutProductVo.setProdBarCode(ObjectUtil.toString(map.get("prodBarCode")));
		stockOutProductVo.setSpecification(ObjectUtil.toString(map.get("specName")));
		stockOutProductVo.setProdNo(ObjectUtil.toString(map.get("prodNo")));
		stockOutProductVo.setCommoName(ObjectUtil.toString(map.get("prodName")));
		stockOutProductVo.setCommoNo(ObjectUtil.toString(map.get("commoNo")));
		stockOutProductVo.setSupNo(ObjectUtil.toString(map.get("code")));
		stockOutProductVo.setSupName(ObjectUtil.toString(map.get("supName")));
		stockOutProductVo.setWhNo(ObjectUtil.toString(map.get("whNo")));
		stockOutProductVo.setWhName(ObjectUtil.toString(map.get("whName")));
		return stockOutProductVo;
	}

	public static List<StockOutProductVo> parseStockOutProductVo(List<Map<String, Object>> maps) {
		if (maps == null) {
			return null;
		}
		List<StockOutProductVo> stockOutProductVos = new ArrayList<StockOutProductVo>();
		for (Map<String, Object> map : maps) {
			StockOutProductVo stockOutProductVo = parseStockOutProductVo(map);
			stockOutProductVos.add(stockOutProductVo);
		}
		return stockOutProductVos;
	}

	/**
	 * 采购单退货出库
	 * 
	 * @param stockOut
	 * @return
	 */
	public static StockOutVo purchaseReturnParseStockOutVo(PurchaseReturnOrderVo purchaseReturn) {
		if (purchaseReturn == null) {
			return null;
		}
		StockOutVo stockOutVo = new StockOutVo();
		stockOutVo.setStockOutTypeNo(purchaseReturn.getPuNo());
		stockOutVo.setReceiverAddr(purchaseReturn.getAddress());
		stockOutVo.setReceiverTel(purchaseReturn.getReceiverTel());
		stockOutVo.setReceiverName(purchaseReturn.getLinkman());
		return stockOutVo;
	}

	public static StockOutProductVo parseStockOutProductVo(PurchaseRequisitionProductVo purchaseRequisitionProduct) {
		if (purchaseRequisitionProduct == null) {
			return null;
		}
		StockOutProductVo stockOutProductVo = new StockOutProductVo();
		stockOutProductVo.setProdNo(purchaseRequisitionProduct.getProductNo());
		stockOutProductVo.setCommoNo(purchaseRequisitionProduct.getCommodityNo());
		stockOutProductVo.setCommoName(purchaseRequisitionProduct.getPpName());
		stockOutProductVo.setProdBarCode(purchaseRequisitionProduct.getProdBarCode());
		stockOutProductVo.setSpecification(purchaseRequisitionProduct.getPpSpecification());
		stockOutProductVo.setStockoutQuantity(ObjectUtil.toLong(purchaseRequisitionProduct.getPpNumber()));
		stockOutProductVo.setSupNo(purchaseRequisitionProduct.getPpSupplierNo());
		stockOutProductVo.setSupName(purchaseRequisitionProduct.getPpSupplierName());
		stockOutProductVo.setWhNo(purchaseRequisitionProduct.getPpWarehouseNo());
		stockOutProductVo.setWhName(purchaseRequisitionProduct.getPpWarehouseName());
		stockOutProductVo.setPurNo(purchaseRequisitionProduct.getPoNo());
		stockOutProductVo.setPurProdNo(purchaseRequisitionProduct.getId());
		return stockOutProductVo;
	}

	public static List<StockOutProductVo> parseStockOutProductVoByPurchase(
			List<PurchaseRequisitionProductVo> purchaseRequisitionProducts) {
		if (purchaseRequisitionProducts == null) {
			return null;
		}
		List<StockOutProductVo> stockOutProductVos = new ArrayList<StockOutProductVo>();
		for (PurchaseRequisitionProductVo purchaseRequisitionProduct : purchaseRequisitionProducts) {
			StockOutProductVo stockOutProductVo = parseStockOutProductVo(purchaseRequisitionProduct);
			stockOutProductVos.add(stockOutProductVo);
		}
		return stockOutProductVos;
	}

	public static StockOutVo purchaseReturnParseStockOutVo(DefectReplceVo purchaseReturnOrderVo) {
		if (purchaseReturnOrderVo == null) {
			return null;
		}
		StockOutVo stockOutVo = new StockOutVo();
		stockOutVo.setStockOutTypeNo(purchaseReturnOrderVo.getDefectReplceId());
		stockOutVo.setReceiverAddr(purchaseReturnOrderVo.getAddress());
		stockOutVo.setReceiverTel(purchaseReturnOrderVo.getReceiverTel());
		stockOutVo.setReceiverName(purchaseReturnOrderVo.getLinkman());
		return stockOutVo;
	}

	public static StockOutProductVo parseStockOutProductVo(DefectReplceVo defectReplces) {
		StockOutProductVo stockOutProductVo = new StockOutProductVo();
		stockOutProductVo.setProdNo(defectReplces.getProdNo());
		stockOutProductVo.setCommoNo(defectReplces.getCommoNo());
		stockOutProductVo.setCommoName(defectReplces.getCommoName());
		stockOutProductVo.setProdBarCode(defectReplces.getProdBarCode());
		stockOutProductVo.setSpecification(defectReplces.getSpecification());
		stockOutProductVo.setStockoutQuantity(ObjectUtil.toLong(defectReplces.getDefectiveNumber()));
		stockOutProductVo.setWhNo(defectReplces.getWhNo());
		stockOutProductVo.setWhName(defectReplces.getWhName());
		stockOutProductVo.setSupNo(defectReplces.getSupCode());
		stockOutProductVo.setSupName(defectReplces.getSupName());
		stockOutProductVo.setDefectReplceName(defectReplces.getDefectReplceName());
		stockOutProductVo.setDefectReplceId(defectReplces.getDefectReplceId());
		stockOutProductVo.setReplceType(defectReplces.getReplceType());
		stockOutProductVo.setProcessState(defectReplces.getProcessState());
		stockOutProductVo.setCreatTime(defectReplces.getCreateTime());
		stockOutProductVo.setInitiater(defectReplces.getInitiater());
		stockOutProductVo.setInitiateTime(defectReplces.getInitiateTime());
//		stockOutProductVo.setReasonsReturn(defectReplces.getReasonsReturn());
		stockOutProductVo.setResonDesc(defectReplces.getDescription());
		stockOutProductVo.setSpecName(defectReplces.getSpecName());
		stockOutProductVo.setPurNo(defectReplces.getPoNo());
		stockOutProductVo.setReasonsReturn(defectReplces.getDefectiveReason());
		return stockOutProductVo;
	}

	public static List<StockOutProductVo> parseStockOutProductVoForDefectReplce(List<DefectReplceVo> defectReplces) {
		List<StockOutProductVo> stockOutProductVos = new ArrayList<StockOutProductVo>();
		for (DefectReplceVo defectReplce : defectReplces) {
			StockOutProductVo stockOutProductVo = parseStockOutProductVo(defectReplce);
			stockOutProductVos.add(stockOutProductVo);
		}
		return stockOutProductVos;
	}
	
	public static List<StockOutProductVo> parseStockOutProductVoByPurchaseReturn(List<PurchaseReturnOrderVo> purchaseReturnOrderVo) {
		if (purchaseReturnOrderVo == null) {
			return null;
		}
		List<StockOutProductVo> stockOutProductVos = new ArrayList<StockOutProductVo>();
		for (PurchaseReturnOrderVo purchaseRequisitionProduct : purchaseReturnOrderVo) {
			StockOutProductVo stockOutProductVo = parseStockOutProductReturnVo(purchaseRequisitionProduct);
			stockOutProductVos.add(stockOutProductVo);
		}
		return stockOutProductVos;
	}
	
	public static StockOutProductVo parseStockOutProductReturnVo(PurchaseReturnOrderVo purchaseReturnOrderVo) {
		if (purchaseReturnOrderVo == null) {
			return null;
		}
		StockOutProductVo stockOutProductVo = new StockOutProductVo();
		stockOutProductVo.setProdNo(purchaseReturnOrderVo.getProdNo());
		stockOutProductVo.setCommoNo(purchaseReturnOrderVo.getCommoNo());
		stockOutProductVo.setCommoName(purchaseReturnOrderVo.getCommodityName());
		stockOutProductVo.setProdBarCode(purchaseReturnOrderVo.getProdNo());
		stockOutProductVo.setSpecification(purchaseReturnOrderVo.getSpecification());
		stockOutProductVo.setStockoutQuantity(ObjectUtil.toLong(purchaseReturnOrderVo.getYieldAmountNumner()));
		stockOutProductVo.setSupNo(purchaseReturnOrderVo.getSupCode());
		stockOutProductVo.setSupName(purchaseReturnOrderVo.getSupName());
		stockOutProductVo.setWhNo(purchaseReturnOrderVo.getPurWhNo());
		stockOutProductVo.setWhName(purchaseReturnOrderVo.getPurWhName());
		stockOutProductVo.setPurNo(purchaseReturnOrderVo.getPoNo());
		stockOutProductVo.setPurProdNo(purchaseReturnOrderVo.getPrId());
		return stockOutProductVo;
	}
}
